package com.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;

import java.io.IOException;

/**
 * 摘自：https://github.com/redisson/redisson/tree/master/redisson-spring-data
 */
@Slf4j
@Configuration
public class RedissonSpringDataConfig {
    public static RedissonClient redissonClient;

    @Bean
    public RedissonClient getRedissonClient(@Value("classpath:/redisson.yaml") Resource configFile) throws IOException {
        Config config = Config.fromYAML(configFile.getInputStream());
        redissonClient = Redisson.create(config);
        log.info("redissonClient id:" + redissonClient.getId());// UUID,如4da53f10-c216-4b2f-b894-c030fd489bf5
        return redissonClient;
    }

}
